package com.ftg.learn.chapter8.treee;

/**
 * 递归
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/8/11 下午3:03
 */
public class RecursiveCall {

    public static int print1(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public static int m1(){
        return 1;
    }

    public static  int m2(){
        return 2 + m1();
    }

    public static  int m3(){
        return 3 + m2();
    }

    public static  int m4(int n){
        //结束条件 (生产环境使用)
        if(n == 1){
            return 1;
        }
        return n + m4(n-1);
    }


    public static void main(String[] args) {
        m4(4);
        System.out.println(print1(10));
    }

}
